<?php
use think\migration\Migrator;
use think\migration\db\Column;

class CreateNanobananaTasks extends Migrator
{
    public function change()
    {
        $this->table('nanobanana_tasks', ['engine' => 'InnoDB', 'comment' => 'Nanobanana图片生成任务表'])
            ->addColumn('user_id', 'integer', ['comment' => '用户ID'])
            ->addColumn('task_id', 'string', ['limit' => 64, 'comment' => '远程任务ID'])
            ->addColumn('type', 'string', ['limit' => 20, 'default' => 'TEXTTOIAMGE', 'comment' => '生成类型：TEXTTOIAMGE或IMAGETOIAMGE'])
            ->addColumn('prompt', 'text', ['null' => true, 'comment' => '文本提示'])
            ->addColumn('num_images', 'integer', ['default' => 1, 'comment' => '生成图片数量'])
            ->addColumn('image_size', 'string', ['limit' => 20, 'default' => '16:9', 'comment' => '图片尺寸'])
            ->addColumn('image_urls', 'text', ['null' => true, 'comment' => '输入图片URL数组JSON（用于图片编辑模式）'])
            ->addColumn('status', 'integer', ['limit' => 1, 'default' => 0, 'comment' => '状态：0待处理,1生成中,2成功,3失败'])
            ->addColumn('result_image_url', 'text', ['null' => true, 'comment' => '结果图片URL'])
            ->addColumn('error_msg', 'string', ['limit' => 500, 'null' => true, 'comment' => '错误信息'])
            ->addColumn('points_consumed', 'integer', ['default' => 0, 'comment' => '消耗积分'])
            ->addColumn('create_time', 'timestamp', ['default' => 'CURRENT_TIMESTAMP', 'comment' => '创建时间'])
            ->addColumn('update_time', 'timestamp', ['null' => true, 'comment' => '更新时间'])
            ->addColumn('complete_time', 'timestamp', ['null' => true, 'comment' => '完成时间'])
            ->addIndex(['task_id'], ['unique' => true, 'name' => 'idx_task_id'])
            ->addIndex(['user_id'], ['name' => 'idx_user_id'])
            ->addIndex(['status'], ['name' => 'idx_status'])
            ->addIndex(['create_time'], ['name' => 'idx_create_time'])
            ->create();
    }
}

